home *** CD-ROM | disk | FTP | other *** search
/ MacGames Sampler / PHT MacGames Bundle.iso / MacSource Folder / Samples from the CD / Editors / emacs / Emacs-1.14b1-sources / sources / mac-emacs-src / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-31  |  4.0 KB  |  203 lines  |  [TEXT/EMAC]

  1. /*
  2.  * Copyright (C) 1993, 1994 Marc Parmet.
  3.  * This file is part of the Macintosh port of GNU Emacs.
  4.  *
  5.  * GNU Emacs is distributed in the hope that it will be useful,
  6.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  8.  * GNU General Public License for more details.
  9.  */
  10.  
  11. #if defined(THINK_C)
  12. #include <MacHeaders>
  13. #else
  14. #include <Types.h>
  15. #include <Memory.h>
  16. #include <Quickdraw.h>
  17. #include <Windows.h>
  18. #include <ToolUtils.h>
  19. #include <SegLoad.h>
  20. #endif
  21.  
  22. #include "config.h"
  23. #include "lisp.h"
  24. #include "regex.h"
  25.  
  26. #if defined(powerc)
  27. QDGlobals qd;
  28. #endif
  29.  
  30. static int
  31. get_preferred_stack_size(void)
  32. {
  33.     int err,stack_size,**sh;
  34.  
  35.     err = get_preference('DATA',129,&sh);
  36.     if (err) return MIN_STACK_SIZE;
  37.     stack_size = **sh;
  38.     DisposHandle((Handle)sh);
  39.     if (stack_size < MIN_STACK_SIZE) return MIN_STACK_SIZE;
  40.     return stack_size;
  41. }
  42.  
  43. static void
  44. load_dumped_data(void)
  45. {
  46.     // Do C initializations not saved in the database
  47.     
  48.     init_alloc_once();
  49.  
  50.     // from init_obarray
  51.     {
  52.         extern int read_buffer_size;
  53.         extern char *read_buffer;
  54.         read_buffer_size = 100;
  55.         read_buffer = (char *) malloc (read_buffer_size);
  56.     }
  57.     
  58.     init_eval_once();
  59.     
  60.     // from syms_of_macros
  61.     {
  62.         extern char *kbd_macro_buffer;
  63.         extern int kbd_macro_bufsize;
  64.         kbd_macro_bufsize = 100;
  65.         kbd_macro_buffer = (char *) malloc (kbd_macro_bufsize);
  66.     }
  67.     
  68.     // from syms_of_minibuf
  69.     {
  70.         extern int minibuf_level;
  71.         extern char *minibuf_prompt;
  72.         extern int minibuf_save_vector_size;
  73.         struct minibuf_save_data {
  74.             char *prompt;
  75.             int prompt_width;
  76.             Lisp_Object help_form;
  77.             Lisp_Object current_prefix_arg;
  78.         };
  79.         extern struct minibuf_save_data *minibuf_save_vector;
  80.         minibuf_level = 0;
  81.         minibuf_prompt = 0;
  82.         minibuf_save_vector_size = 5;
  83.         minibuf_save_vector = (struct minibuf_save_data *) malloc (5 *
  84.             sizeof (struct minibuf_save_data));
  85.     }
  86.     
  87.     // from syms_of_search
  88.     {
  89.         register int i;
  90.         extern int re_max_failures;
  91.         extern unsigned char downcase_table[];
  92.         extern struct re_pattern_buffer searchbuf;
  93.         extern char search_fastmap[];
  94.         
  95.         /* Avoid running out of regexp stack quite so soon.*/
  96.         re_max_failures = 10000;
  97.         
  98.         for (i = 0; i < 0400; i++) {
  99.             downcase_table[i] = (i >= 'A' && i <= 'Z') ? i + 040 : i;
  100.             downcase_table[0400+i] =
  101.                 ((i >= 'A' && i <= 'Z')    ? i + ('a' - 'A')
  102.                                         : ((i >= 'a' && i <= 'z') ?    i + ('A' - 'a')
  103.                                                                 : i));
  104.         }
  105.         
  106.         searchbuf.allocated = 100;
  107.         searchbuf.buffer = (char *) malloc (searchbuf.allocated);
  108.         searchbuf.fastmap = search_fastmap;
  109.     }
  110.  
  111.     // Load the database
  112.     reverse_unexec();
  113. }
  114.  
  115. void
  116. main(void)
  117. {
  118.     char ***argv;
  119.     int argc,stack_needed;
  120.     KeyMap keys;
  121.     extern char **environ;
  122.     extern int initialized;
  123.     extern int *pure;
  124.     
  125.     stack_needed = get_preferred_stack_size() * 1024;
  126.     init_unix(stack_needed,&environ,&argc,&argv);
  127.     check_traps();
  128.     AEObjectInit();
  129.  
  130.     GetKeys(keys);
  131.     if (BitTst(keys,61)) { /* Test option key */
  132.         // Rebuild the database.
  133.         static char *dump_argv[] = { 0L, "-batch", "-l", "loadup.el", "dump" };
  134.         int i,dump_argc = sizeof(dump_argv) / sizeof(char *);
  135.  
  136.         SetHandleSize((Handle)argv,(dump_argc+1) * sizeof(char *));
  137.         if (MemError()) ExitToShell();
  138.         for (i = 1; i<dump_argc; ++i)
  139.             (*argv)[i] = dump_argv[i];
  140.         (*argv)[dump_argc] = 0L;
  141.         argc = dump_argc;
  142.         initialized = 0;
  143.     }
  144.     else if (BitTst(keys,63)) /* Test shift key */
  145.         // Start up in impure state, no load
  146.         initialized = 0;
  147.     else {
  148.         // Usual startup.  Load the database.
  149.         load_dumped_data();
  150.         initialized = 1;
  151.     }
  152.     
  153.     if (!initialized) {
  154.         // Set up pure storage area
  155.         char **h = NewHandle(PURESIZE);
  156.         if (MemError()) ExitToShell();
  157.         MoveHHi(h);
  158.         HLock(h);
  159.         pure = (int *)StripAddress(*h);
  160.     }
  161.  
  162.     MoveHHi((Handle)argv);
  163.     HLock((Handle)argv);
  164.     main1(argc,*argv,environ);
  165. }
  166.  
  167. #if defined(powerc)
  168.  
  169. void
  170. CtoPstr(char *s)
  171. {
  172.     char c,d,*t;
  173.  
  174.     t = s;
  175.     d = '\0';
  176.     while (1) {
  177.         c = *s;
  178.         *s = d;
  179.         d = c;
  180.         if (c == '\0') {
  181.             *t = s - t;
  182.             return;
  183.         }
  184.         ++s;
  185.     }
  186. }
  187.  
  188. void
  189. PtoCstr(unsigned char *s)
  190. {
  191.     int n;
  192.  
  193.     n = s[0];
  194.     while (n != 0) {
  195.         s[0] = s[1];
  196.         ++s;
  197.         --n;
  198.     }
  199.     s[0] = '\0';
  200. }
  201.  
  202. #endif
  203.